package br.ufrn.sigtcc.controller.cadastros;

import java.util.logging.Logger;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import org.primefaces.event.FlowEvent;

import br.ufrn.sigtcc.controller.cadastros.interfaces.IControleCadastroAdmin;
import br.ufrn.sigtcc.controller.services.AdminServiceImpl;
import br.ufrn.sigtcc.model.entidades.Admin;
import br.ufrn.sigtcc.model.entidades.Endereco;
import br.ufrn.sigtcc.model.entidades.Telefone;
import br.ufrn.sigtcc.util.exceptions.BDException;
import br.ufrn.sigtcc.util.exceptions.BusinessException;

public class ControleCadastroAdmin extends AdminServiceImpl implements IControleCadastroAdmin{
	
	public ControleCadastroAdmin() {
		// TODO Auto-generated constructor stub
	}
	
	
	
	private Admin admin =  new Admin();
	private Endereco endereco =  new Endereco();
	private Telefone telefone =  new Telefone();
	public Admin getAdmin() {
		return admin;
	}
	public void setAdmin(Admin admin) {
		this.admin = admin;
	}
	public Endereco getEndereco() {
		return endereco;
	}
	public void setEndereco(Endereco endereco) {
		this.endereco = endereco;
	}
	public Telefone getTelefone() {
		return telefone;
	}
	public void setTelefone(Telefone telefone) {
		this.telefone = telefone;
	}
	@Override
	public void cadastrarAdmin() throws BDException, BusinessException {
		
//		admin.setEndereco(endereco);
//		admin.setTelefone(telefone);
		cadastrarAdmin(admin); 
		
	}
	@Override
	public void removerAdmin() throws BDException, BusinessException {

		removerAdmin(admin);
	}
	@Override
	public void atualizarAdmin() throws BDException, BusinessException {
		atualizarAdmin(admin);
	}
	
private boolean skip;
	
	private static Logger logger = Logger.getLogger(ControleCadastroAdmin.class.getName());

	public void cadastrarAdmin(ActionEvent actionEvent) throws BDException, BusinessException {

		cadastrarAdmin();
		
		FacesMessage msg = new FacesMessage("Sucesso", "Bem Vindo :" + admin.getNome());
		FacesContext.getCurrentInstance().addMessage(null, msg);
	}
	
	public boolean isSkip() {
		return skip;
	}

	public void setSkip(boolean skip) {
		this.skip = skip;
	}
	
	public String onFlowProcess(FlowEvent event) {
		logger.info("Passo Corrente:" + event.getOldStep());
		logger.info("Proximo passo:" + event.getNewStep());
		
		if(skip) {
			skip = false;	
			return "confirm";
		}
		else {
			return event.getNewStep();
		}
	}
	
	
}
